<?php
                                                                                                                                                                                                                                                                                                                                        
// TTTTTTTTTTTTTTTTTTTTTTT                  MMMMMMMM               MMMMMMMM                                CCCCCCCCCCCCMMMMMMMM               MMMMMMMM  SSSSSSSSSSSSSSS 
// T:::::::::::::::::::::T                  M:::::::M             M:::::::M                             CCC::::::::::::M:::::::M             M:::::::MSS:::::::::::::::S
// T:::::::::::::::::::::T                  M::::::::M           M::::::::M                           CC:::::::::::::::M::::::::M           M::::::::S:::::SSSSSS::::::S
// T:::::TT:::::::TT:::::T                  M:::::::::M         M:::::::::M                          C:::::CCCCCCCC::::M:::::::::M         M:::::::::S:::::S     SSSSSSS
// TTTTTT  T:::::T  TTTTTppppp   ppppppppp  M::::::::::M       M::::::::::M   eeeeeeeeeeee          C:::::C       CCCCCM::::::::::M       M::::::::::S:::::S            
//         T:::::T       p::::ppp:::::::::p M:::::::::::M     M:::::::::::M ee::::::::::::ee       C:::::C             M:::::::::::M     M:::::::::::S:::::S            
//         T:::::T       p:::::::::::::::::pM:::::::M::::M   M::::M:::::::Me::::::eeeee:::::ee     C:::::C             M:::::::M::::M   M::::M:::::::MS::::SSSS         
//         T:::::T       pp::::::ppppp::::::M::::::M M::::M M::::M M::::::e::::::e     e:::::e     C:::::C             M::::::M M::::M M::::M M::::::M SS::::::SSSSS    
//         T:::::T        p:::::p     p:::::M::::::M  M::::M::::M  M::::::e:::::::eeeee::::::e     C:::::C             M::::::M  M::::M::::M  M::::::M   SSS::::::::SS  
//         T:::::T        p:::::p     p:::::M::::::M   M:::::::M   M::::::e:::::::::::::::::e      C:::::C             M::::::M   M:::::::M   M::::::M      SSSSSS::::S 
//         T:::::T        p:::::p     p:::::M::::::M    M:::::M    M::::::e::::::eeeeeeeeeee       C:::::C             M::::::M    M:::::M    M::::::M           S:::::S
//         T:::::T        p:::::p    p::::::M::::::M     MMMMM     M::::::e:::::::e                 C:::::C       CCCCCM::::::M     MMMMM     M::::::M           S:::::S
//       TT:::::::TT      p:::::ppppp:::::::M::::::M               M::::::e::::::::e                 C:::::CCCCCCCC::::M::::::M               M::::::SSSSSSS     S:::::S
//       T:::::::::T      p::::::::::::::::pM::::::M               M::::::Me::::::::eeeeeeee          CC:::::::::::::::M::::::M               M::::::S::::::SSSSSS:::::S
//       T:::::::::T      p::::::::::::::pp M::::::M               M::::::M ee:::::::::::::e            CCC::::::::::::M::::::M               M::::::S:::::::::::::::SS 
//       TTTTTTTTTTT      p::::::pppppppp   MMMMMMMM               MMMMMMMM   eeeeeeeeeeeeee               CCCCCCCCCCCCMMMMMMMM               MMMMMMMMSSSSSSSSSSSSSSS   
//                        p:::::p                                                                                                                                       
//                        p:::::p                                                                                                                                       
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       ppppppppp                                                                                                                                      
                                                                                                                                                                     
//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/07/3
//      |_|                                         | TpMeCMS

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Config;
/**
 * 公共无需登陆接口
 * @ApiInternal()
 */
class Tpmecmscom extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];


//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/2
//      |_|                                         | TpMeCms Start





//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/2
//      |_|                                         | TpMeCms End

  
    /**
     * 可在继承app\common\controller\Tpmecms 下面的里面直接使用该控制器里面的方法 使用方法：$this->p_tpmecsm();
     *
     * @return void
     */
    protected function p_tpmecms()
    {
        $this->success('TpMeCms', ['com' => 'TpMeCMS']);
    }


    /**
     * 推送发布订单消息
     *
     * @param int $order_status 订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=顺风车
     * @param int $order_id 订单号
     * @return void
     */
    protected function PushOrderMsg($order_status,$order_id)
    {
        //发布给全部的用户 
        // $Sysmsg =  new \app\api\controller\Sysmsg;
        // $Sysmsg->SendSysMsgUser($uid=null,$type=null,$content=null,$order_id=null,$order_status=null);


        // * @param string $uid 用户
        // * @param string $type 类型:1=新普通发货,2=新城市快运,3=新拉货搬家,4=新顺风车,6=接单消息,7=坐标位置,8=用户消息,9=系统消息,10=订单状态修改
        // * @param string $content 内容
        // * @param string $order_id 订单id
        // * @param string $order_status 订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=顺风车
 
    }

    /**
     * 推送接单消息给用户
     *
     * @param int $order_status 订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=顺风车
     * @param int $order_id 订单号
     * @return void
     */
    protected function PushGrabOrderMsg($order_status,$order_id)
    {
        //发布给固定的用户 

    }



//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/14
//      |_|                                         | TpMeCms 🌏Start







    /**
     * 更新坐标加油站
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function UpdateGeoPfs($lng=null,$lat=null,$id)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            $geo->add_geo($lng,$lat,$id,'geo_pfs');
        }
    }
    
    /**
     * 获取附近加油站
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @return void
     */
    public function GetNearbyGeoPfs($lng=null,$lat=null)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            return $geo->get_nearby_list($lng,$lat,8000,'km',99999,'ASC','geo_pfs');
        }
    }

    /**
     * 删除坐标加油站
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function DelGeoPfs($id)
    {
        $geo = new \addons\redisgeo\controller\Index();
        $geo->del_geo($id,'geo_pfs');
    }

    //————————————————————————————————————————————————————————————————————————————————————


    /**
     * 更新坐标维修店铺
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function UpdateGeoRepair($lng=null,$lat=null,$id)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            $geo->add_geo($lng,$lat,$id,'geo_repair');
        }
    }

    /**
     * 获取附近维修店铺
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @return void
     */
    public function GetNearbyGeoRepair($lng=null,$lat=null)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            return $geo->get_nearby_list($lng,$lat,8000,'km',99999,'ASC','geo_repair');
        }
    }

    /**
     * 删除坐标维修店铺
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function DelGeoRepair($id)
    {
        $geo = new \addons\redisgeo\controller\Index();
        $geo->del_geo($id,'geo_repair');
    }

    //————————————————————————————————————————————————————————————————————————————————————


    /**
     * 更新坐标物流专线
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function UpdateGeoLogistics($lng=null,$lat=null,$id)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            $geo->add_geo($lng,$lat,$id,'geo_logistics');
        }
    }

    /**
     * 获取附近物流专线
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @return void
     */
    public function GetNearbyGeoLogistics($lng=null,$lat=null)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            return $geo->get_nearby_list($lng,$lat,8000,'km',99999,'ASC','geo_logistics');
        }
    }

    /**
     * 删除坐标物流专线
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function DelGeoLogistics($id)
    {
        $geo = new \addons\redisgeo\controller\Index();
        $geo->del_geo($id,'geo_logistics');
    }

    //————————————————————————————————————————————————————————————————————————————————————

    /**
     * 更新坐标二手车店铺
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function UpdateGeoCarStore($lng=null,$lat=null,$id)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            $geo->add_geo($lng,$lat,$id,'geo_car_store');
        }
    }

    /**
     * 获取附近物流专线
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @return void
     */
    public function GetNearbyGeoCarStore($lng=null,$lat=null)
    {
        if($lng && $lat){
            $geo = new \addons\redisgeo\controller\Index();
            return $geo->get_nearby_list($lng,$lat,8000,'km',99999,'ASC','geo_car_store');
        }
    }

    /**
     * 删除坐标二手车店铺
     * @ApiInternal()
     * @param string $lng 经度
     * @param string $lat 纬度
     * @param string $id ID
     * @return void
     */
    public function DelGeoCarStore($id)
    {
        $geo = new \addons\redisgeo\controller\Index();
        $geo->del_geo($id,'geo_car_store');
    }


//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/14
//      |_|                                         | TpMeCms 🌏End


    /**
     * 添加地址使用数🌍
     *
     * @param int $id 地址id
     * @return void
     */
    protected function AddAddrUseNum($id)
    {
        Db::name('addr')->where('id',$id)->setInc('use_num');

    }

    /**
     * 添加地址🌍
     *
     * @param string $addr 地址
     * @param string $uid 用户
     * @param string $status 状态类型1=未知,2=发货地,3=收货地
     * @param string $tel 电话
     * @param string $name 姓名
     * @param string $city 城市
     * @param string $lat 纬度
     * @param string $lng 经度
     * @return void
     */
    protected function AddAddr($addr,$uid,$status='1',$tel=null,$name=null,$city=null,$lat=null,$lng=null)
    {
        $data['uid'] = $uid;
        $data['addr'] = $addr;
        $data['tel'] = $tel;
        $data['name'] = $name;
        $data['not_del'] = 1;

        $res = Db::name('addr')->where($data)->find();
        if(!$res){
           

            $data['lng'] = $lng;
            $data['lat'] = $lat;
            $data['city'] = $city;
            $data['status'] = $status;
            $data['use_num'] = 1;
            $data['time'] = time();
            $data['id'] = Db::name('addr')->insertGetId($data);
            return $data['id'];
        }

        return $res['id'];
    }

    /**
     * 获取我的地址列表🌍
     *
     * @param string $uid 用户
     * @param string $status 状态
     * @return void
     */
    protected function GetMyAddrList($uid,$status=null)
    {
        $data['uid'] = $uid;
        if($status)
        $data['status'] = $status;
        $data['not_del'] = 1;

        $list = Db::name('addr')
                ->where($data)
                ->order('use_num desc')
                ->order('time desc')
                ->select();
        return $list;
    }

    /**
     * 获取地址信息🌍
     *
     * @param int $id 地址id
     * @return void
     */
    protected function GetAddrData($id)
    {
        return Db::name('addr')->where('id',$id)->find();
    }

    /**
     * 获取地址城市Ids🌍
     *
     * @param int $city 地址city
     * @return void
     */
    protected function GetAddrCityIds($city)
    {
        return Db::name('addr')->where('city',$city)->column('id');
    }

    
    /**
     * 获取标签列表
     *
     * @return void
     */
    protected function GetTagList()
    {
        $cate_list = Db::name('tagcate')->order('weigh desc')->select();
        // $list = Db::name('tag')->order('tagcate_id desc')->column('*','tagcate_id');
        foreach($cate_list as $k => &$v){
            unset($temp);
            $temp = Db::name('tag')->where('tagcate_id',$v['id'])->select();
            $v['list'] = $temp;
        }
        return $cate_list;
    }



    /**
     * 获取城市/搬家标签列表
     *
     * @return void
     */
    protected function GetTag2List()
    {
        $cate_list = Db::name('tagcate2')->order('weigh desc')->select();
        // $list = Db::name('tag')->order('tagcate_id desc')->column('*','tagcate_id');
        foreach($cate_list as $k => &$v){
            unset($temp);
            $temp = Db::name('tag2')->where('tagcate2_id',$v['id'])->select();
            $v['list'] = $temp;
        }
        return $cate_list;
    }

    /**
     * 转换订单1押金
     *
     * @param string $price 估价价格
     * @return void
     */
    public function ChangeOrder1Deposit($price)
    {
        if($price<200){
            return 50;
        }elseif(200 <= $price && $price <500){
            return 100;
        }elseif(500 <= $price && $price <1000){
            return 150;
        }else{
            return 200;
        }
    }




    
    // 算距离

    // 估算2地的价格




    /**
     * 获取汽车信息🚚
     * @ApiInternal()
     * @return void
     */
    public function GetCarData($id)
    {
        return Db::name('car')->find($id);
    }





    /**
     * 计算价格订单二
     *
     * @param int $car_id 车id
     * @param int $s_addr_id 发货地址id
     * @param int $e_addr_id 卸货地址id
     * @return void
     */
    protected function CalculatePriceOrder2($car_id,$s_addr_id,$e_addr_id)
    {
        $car = $this->GetCarData($car_id);
        
        $km = $this->CalculateDistance($s_addr_id,$e_addr_id);
        if($km<0.1){
            $this->error('地址距离有误',$km);
        }
        $money = $car['price1'];//总价
        if($km<=5 && $km>0){
            
        }elseif($km>5 && $km<26){
            $money = $money + ($km-5)*$car['price2'];
        }elseif($km>=26){
            $money = $money + ($km-5)*$car['price3'];
        }

        return $money;
    }



    /**
     * 计算全部距离
     *
     * @param int $s_addr_id 装货地址
     * @param int $s2_addr_id 装货地址2
     * @param int $e_addr_id 卸货地址
     * @param int $e2_addr_id 卸货地址2  
     * @return void
     */
    protected function CalculateDistanceAll($s_addr_id,$s2_addr_id=null,$e_addr_id,$e2_addr_id=null)
    {
        $km = 0;
        if($s2_addr_id){
            $km = $this->CalculateDistance($s_addr_id,$s2_addr_id);
            $km = $km + $this->CalculateDistance($s2_addr_id,$e_addr_id);
          
            if($e2_addr_id){
                $km = $km + $this->CalculateDistance($e_addr_id,$e2_addr_id);
            }
        }else{
          
            $km = $this->CalculateDistance($s_addr_id,$e_addr_id);
            if($e2_addr_id){
                $km = $km + $this->CalculateDistance($e_addr_id,$e2_addr_id);
            }
        }
        return $km;
        // $this->success('ok',$km);
    }

    /**
     * 计算全部距离2
     *
     * @param string $addr_ids 地址id按顺序排列
     * @return void
     */
    protected function CalculateDistanceAll2($addr_ids)
    {
        // halt($addr_ids);
        $km = 0;
        $s_addr_id = null;
        foreach ($addr_ids as $key => $e_addr_id) {
            if($s_addr_id && $e_addr_id){
                $km = $km + $this->CalculateDistance($s_addr_id,$e_addr_id);

            }
            $s_addr_id = $e_addr_id;
            
        }
        return $km;
      
    }



    /**
     * 计算距离
     *
     * @param int $s_addr_id 发货地址id
     * @param int $e_addr_id 卸货地址id
     * @return void
     */
    protected function CalculateDistance($s_addr_id,$e_addr_id)
    {
        $s = $this->GetAddrData($s_addr_id);
        $e = $this->GetAddrData($e_addr_id);
        return round($this->get_coordinate_distance($s['lng'], $s['lat'], $e['lng'], $e['lat']),2);
        // 示例https://lbsyun.baidu.com/index.php?title=webapi/route-matrix-api-v2
        // 服务地址-驾车
        // http://api.map.baidu.com/routematrix/v2/driving?  //GET请求


        // https://lbsyun.baidu.com/index.php?title=webapi/route-matrix-truck
        // 功能介绍
        // 货车批量算路
        // 1. 支持全国同城/跨城批量算路，一次请求支持计算50条路线的实际行驶距离和耗时
        // 2. 支持规避物理四限：高、宽、重、轴重
        // 3. 支持根据车牌号规避交规限行，支持区分蓝/黄/白/绿/黑车牌
        // 4. 支持依据实时路况计算路线距离和耗时

        // 5. 支持依据未来3天预测路况和道路限行，规划未来出行距离和耗时
        // 6. 支持多种路线策略选择，包括省钱路线、不走高速、高速优先等策略
        // 7. 支持规避自定义区域
    }




    /**
     * 计算坐标距离
     * 
     * @ApiInternal()
     * @param $lng1 经度1
     * @param $lat1 纬度1
     * @param $lng2 经度2
     * @param $lat2 纬度2
     * @return float
     */
    public function get_coordinate_distance($lng1=120.459799, $lat1=31.802264, $lng2=120.326568, $lat2=31.686598) 
    { 
        $radLat1=deg2rad($lat1);//deg2rad()函数将角度转换为弧度
        $radLat2=deg2rad($lat2);
        $radLng1=deg2rad($lng1);
        $radLng2=deg2rad($lng2);
        $a=$radLat1-$radLat2;
        $b=$radLng1-$radLng2;
        $s=2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6378.137;
        return $s;
    }


    // /**
    //  * 订单获取零担价格_订单号
    //  * @ApiInternal()
    //  * @param string $order 订单
    //  * @return void
    //  */
    // public function OrderGetBulkloadPrice($order){
    //     if(!is_array($order)){
    //         $order = Db::name('order1')->where('order',$order)->find();
    //     }
    //     return $this->Long_Wide_High_GetBulkloadPrice($order);
    // }    

    // /**
    //  * 长宽高获取价格
    //  * 
    //  * @ApiInternal()
    //  *
    //  * @param array $order 数组
    //  * @param integer $long 货物长
    //  * @param float $wide 货物宽
    //  * @param integer $high 货物高
    //  * @param integer $km 2地距离km
    //  * @param integer $t 货物重量吨
    //  * @return void
    //  */
    // public function Long_Wide_High_GetBulkloadPrice($order=null,$long = 3,$wide = 1.5,$high = 2,$km = 300,$t = 1)
    // {
    //     if(!$order){
    //         $order['long'] = $long;
    //         $order['wide'] = $wide;
    //         $order['high'] = $high;
    //         $order['km'] = $km;
    //         $order['t'] = $t;
    //     }



    //     $num_arr[] = $order['long'];
    //     $num_arr[] = $order['wide'];
    //     $num_arr[] = $order['high'];
    //     $long=0;
    //     foreach($num_arr as $key=>$val){
    //         if($long<$val){
    //             $long = $val;                
    //         }
    //     }

    //     $wide_high = $num_arr;//定义宽高
    //     foreach($wide_high as $key=>$val){
    //         if($long==$val){
    //             unset($wide_high[$key]);
    //             break;           
    //         }
    //     }

    //     $wide_high = array_merge($wide_high);
         
    //     //宽高
    //     if($wide_high[0]>$wide_high[1]){
    //             //超
    //         if($wide_high[0] >= 2 && $wide_high[1] >= 1.5){
    //             $price = $this->GetBulkload2Price($order['km'],$order['t']);
    //         }else{
    //             //不超宽高
    //             $price = $this->GetBulkload1Price($order['km'],$order['t']);
    //         }

    //     }else{
    //         //超
    //         if($wide_high[1] >= 2 && $wide_high[0] >= 1.5){
    //             $price = $this->GetBulkload2Price($order['km'],$order['t']);
    //         }else{
    //             //不超宽高
    //             $price = $this->GetBulkload1Price($order['km'],$order['t']);
    //         }
    //     }

    //     return $price;
    //     halt($price);
     

    //     // $wide_high = array_merge(array_diff($num_arr, [$long]));
    //     // halt($wide_high);

    //     // $res = Db::name('bulkload')->where('max',$km)->find();
    //     // if(!$res){
    //     //     $res = Db::name('bulkload')->where('min','<',$km)->where('max','>',$km)->find();
    //     //     if(!$res){
    //     //         $this->error('请输入正确的公里数');
    //     //     }
    //     // }
    //     // return $res;
    // }

    // /**
    //  * 获取零担超高1.5超宽2米
    //  * @ApiInternal()
    //  * 
    //  * @param float $km 公里
    //  * @param float $t 吨
    //  * @return void
    //  */
    // public function GetBulkload2Price($km,$t=1)
    // {
    //     $res = Db::name('bulkload2')->where('max',$km)->find();
    //     if(!$res){
    //         $res = Db::name('bulkload2')->where('min','<',$km)->where('max','>',$km)->find();
    //         if(!$res){
    //             $this->error('请输入正确的公里数');
    //         }
    //     }
    //     return round($res['price'] * $km * ceil($t),2);//单价*公里*吨
    //     return $res;
    // }

    // /**
    //  * 获取零担不超
    //  * @ApiInternal()
    //  * 
    //  * @param float $km 公里
    //  * @param float $t 吨
    //  * @return void
    //  */
    // public function GetBulkload1Price($km,$t=1)
    // {
    //     $res = Db::name('bulkload')->where('max',$km)->find();
    //     if(!$res){
    //         $res = Db::name('bulkload')->where('min','<',$km)->where('max','>',$km)->find();
    //         if(!$res){
    //             $this->error('请输入正确的公里数');
    //         }
    //     }
    //     return round($res['price'] * $km * ceil($t),2);//单价*公里*吨
    //     return $res;
    // }








    /**
     * 支付订单押金
     * @ApiInternal()
     * @param string $order_id 订单id
     * @param string $order_status 1=普通发货,2=城市快运,3=拉货搬家,4=顺风车
     * @param string $uid 用户id
     * @param string $role_status 角色:1=货主,2=司机
     * @param string $pay_type 支付类型:1=微信,2=支付宝,3=钱包
     * @return void
     */
    public function PayOrder($order_id,$order_status,$uid,$role_status='1',$pay_type = '3')
    {
  
            
        $where_order['id'] = $order_id;
        // $where_order['uid'] = $uid;
        
        //订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=专线
        switch ($order_status) {
            case '1':
                $db = 'order1';
                break;
            case '2':
                $db = 'order2';
                break;
            case '3':
                $db = 'order2';
                break;
            case '4':
                $db = 'order_return';
                break;
            
            default:
                $this->error('暂无此类型订单');
                break;
        }
       
        //查询订单
        $order = Db::name($db)->where($where_order)->find();
     
        if(!$order){
            $this->error('没有该订单信息');
        }
    
        //支付订单查询
        $where_pay_order['order_id'] = $order_id;
        $where_pay_order['uid'] = $uid;
        $where_pay_order['order_status'] = $order_status;
        $where_pay_order['role_status'] = $role_status;
        // halt($where_pay_order);
        $pay_status_order = Db::name('pay_order')->where($where_pay_order)->where('pay_status','2')->find();
        if($pay_status_order){
            $this->error('已支付',$pay_status_order);
        }
        $pay_order = Db::name('pay_order')->where($where_pay_order)->where('pay_status','1')->find();
        
        

        //没有支付订单信息 插入
        if(!$pay_order){
            $pay_order = $where_pay_order;
            $pay_order['pay_status'] = '1';//支付状态:1=待支付,2=已支付,3=已退款,4=已超时
            $pay['role_status'] = $role_status;
            //角色
            switch ($role_status) {
                case '1':
                    $pay_order['money'] = $order['s_money'];
                    $prefix = 'OrderS';
                    break;
                case '2':
                    $pay_order['money'] = $order['j_money'];
                    $prefix = 'OrderJ';
                    break;
                default:
                    $pay_order['money'] = 9999;
                    $prefix = 'Order';
                    break;
            }
            $pay_order['order'] = $this->rand_order($prefix,$uid,20);
            $pay_order['time'] = time();
            $pay_order['pay_type'] = $pay_type;
            $pay_order['role_status'] = $role_status;
            

            $pay_order['id'] = Db::name('pay_order')->insertGetId($pay_order);

            
        }else{
          
            //如果支付不相同就修改 
            if( $pay_order['pay_type'] != $pay_type){
                Db::name('pay_order')->where('id',$pay_order['id'])->update(['pay_type'=>$pay_type]);
            }
        }

        //支付
        $Pay = new \app\api\controller\Pay($role_status);
        switch ($pay_type) {
            case '1':
                return $Pay->wx_pay_order($pay_order); 
                break;
            case '2':
                return $Pay->ali_pay_order($pay_order); 
                break;
            case '3':
                $this->MoneyPay($uid,$pay_order['money'],'支付押金'.$pay_order['order']);



                $pay_data['pay_status'] = '2';//支付状态:1=待支付,2=已支付,3=已退款,4=已超时
                $pay_data['pay_time'] = time();//支付时间
                $pay_data['pay_type'] = '3';    //支付类型:1=微信,2=支付宝,3=钱包，9=其他
                $pay_data['pay_money'] = intval($pay_order['money']*100);//实际支付的金额 分

             
                $res_up = Db::name('pay_order')
                        ->where('order',$pay_order['order'])
                        ->update($pay_data);
                    
                //修改主订单  订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=专线
                $db = $this->GetTableByOrderStatus($order_status);
             
                //角色:1=货主,2=司机
                switch ($role_status) {
                    case '1':
                        $pay_status['spay_status'] = '1';
                        $pay_status['pay_time'] = time();
                        break;
                    case '2':
                        $pay_status['jpay_status'] = '1';
                        break;
                    default:
                        # code...
                        break;
                }
                Db::name($db)->where('id',$order_id)->update($pay_status);

                $this->PushOrderMsg($order_status,$pay_order['id']);//推送发布订单消息

                $this->success('钱包支付成功',$pay_data,3);
                break;
            default:
                $this->error('暂未开通此项支付');
                break;
        }
        
       
    }


    /**
     * 钱包支付
     *
     * @param int $uid 用户id
     * @param int $money 钱
     * @param string $ps 备注
     * @return bool
     */
    protected function MoneyPay($uid,$money,$ps=null)
    {
        $user = Db::name('user')->where('id',$uid)->find();
        // $money = $user['money'];

        if($user['money']<$money){
            $this->error('钱包余额不足!',$money,-3);
        }

        //减去用户的钱包余额
        $this->DecUserMoney($uid,$money,$ps);
    }




 


//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/2
//      |_|                                         | 获取订单信息 Start



    /**
     * 获取表_订单类型:1=普通发货,2=城市快运,3=拉货搬家,4=回程车
     * @ApiInternal()
     * @param string $order_status
     * @return void
     */
    public function GetTableByOrderStatus($order_status)
    {
        switch ($order_status) {
            case '1':
                return 'order1';
                break;
            case '2':
                return 'order2';
                break;
            case '3':
                return 'order2';
                break;    
            case '4':
                return 'order_return';
                break;
        
            default:
                // return 'order1';
                break;
        }
    }

    /**
     * 获取订单1信息（普通发货订单）
     * 
     * @ApiInternal()
     * @param int $order_id 订单id
     * @return void
     */
    public function GetOrder1Data($order_id)
    {
        $val = Db::name('order1')->find($order_id);
        if($val){

            $val = $this->GetOrder1FieldData($val);
            // $val['s_addr'] = $this->GetAddrData($val['s_addr_id']);
            // $val['e_addr'] = $this->GetAddrData($val['e_addr_id']);
            // if($val['s2_addr_id']>0)
            //     $val['s2_addr'] = $this->GetAddrData($val['s2_addr_id']);
            // if($val['e2_addr_id']>0)
            //     $val['e2_addr'] = $this->GetAddrData($val['e2_addr_id']);
        }
        return $val;
    }



    /**
     * 司机获取订单1信息（普通发货订单）
     * 
     * @ApiInternal()
     * @param int $order_id 订单id
     * @return void
     */
    public function DriverGetOrder1Data($order_id)
    {
        $val = Db::name('order1')->find($order_id);
        if($val){

            $val = $this->GetOrder1FieldData($val);
            if($val['j_uid']){ //如果有人接单了 判断是否是自己
                if($val['j_uid']!=$this->auth->id){
                    $this->error('已被抢单');
                }
            }
            $val['user'] = $this->GetSuserData($val['s_uid']);

        }else{
            $this->error('没有该订单信息');
        }
        return $val;
    }






    /**
     * 获取用户的信息
     *
     * @param int $uid 用户id
     * @return void
     */
    protected function GetSuserData($uid)
    {
        return Db::name('user')
                ->where('id',$uid)
                ->field('id,username,nickname,mobile,avatar,group_id,svip_year,svip,svip_etime,rule_status,s_trade')
                ->find();
    }


    // `verification` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '验证',
    // `wx_openid` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '微信openid',
    // `openid` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '小程序openid',
    // `unionid` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '开放平台',
    // `sex` enum('0','1','2') COLLATE utf8mb4_unicode_ci DEFAULT '0' COMMENT '性别:1=男,2=女,0=未知',
    // `city` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '城市',
    // `ltd_name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公司名称',
    // `jvip_etime` int(10) unsigned DEFAULT NULL COMMENT '司机VIP到期时间',
    // `jvip` enum('1','2') COLLATE utf8mb4_unicode_ci DEFAULT '1' COMMENT '司机VIP:1=普通司机,2=VIP',
    // `rule_status` enum('0','1','2','3','4') COLLATE utf8mb4_unicode_ci DEFAULT '0' COMMENT '第二角色:0=无,1=加油站,2=二手车卖家,3=车辆维修,4=物流专线',
    // `sfz1_image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '身份证正面照',
    // `sfz2_image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '身份证背面照',
    // `drive_images` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '驾驶证照片',
    // `driving_images` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '行驶证照片',
    // `name` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '姓名',
    // `sfz_number` varchar(18) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '身份证号码',
    // `svip_etime` int(10) DEFAULT NULL COMMENT '发货人VIP到期时间',
    // `svip` enum('1','2') COLLATE utf8mb4_unicode_ci DEFAULT '1' COMMENT '发货人VIP:1=普通用户,2=VIP',
    // `svip_year` int(5) DEFAULT '0' COMMENT '发货人开通年',
    // `jvip_year` int(5) DEFAULT NULL COMMENT '司机已开通年',
    /**
     * 获取司机的信息
     *
     * @param int $uid 用户id
     * @return void
     */
    protected function GetJuserData($uid)
    {
        return Db::name('user')
                ->where('id',$uid)
                ->field('id,username,nickname,mobile,avatar,group_id,jvip_year,jvip_year,jvip,ltd_name,rule_status')
                ->find();
    }


    /**
     * 获取订单1信息（普通发货订单）
     * 
     * @ApiInternal()
     * @param int $val 内容
     * @return void
     */
    public function GetOrder1FieldData($val)
    {
     
        if($val){
            $val['s_addr'] = $this->GetAddrData($val['s_addr_id']);
            $val['e_addr'] = $this->GetAddrData($val['e_addr_id']);
            if($val['s2_addr_id']>0)
                $val['s2_addr'] = $this->GetAddrData($val['s2_addr_id']);
            if($val['e2_addr_id']>0)
                $val['e2_addr'] = $this->GetAddrData($val['e2_addr_id']);
            $val['tag_list'] =Db::name('tag')->where('id','in',$val['tag_ids'])->select();

            switch ($val['lay_status']) {
                case '1':
                    $val['lay'] = '一装一卸';
                    break;
                case '2':
                    $val['lay'] = '一装两卸';
                    break;
                case '3':
                    $val['lay'] = '两装一卸';
                    break;
                case '4':
                    $val['lay'] = '两装两卸';
                    break;                
                default:
                    $val['lay'] = '未知';
                    break;
            }

            switch ($val['load_status']) {
                case '1':
                    $val['load'] = '整车';
                    break;
                case '2':
                    $val['load'] = '零担';
                    break;                
                default:
                    $val['load'] = '未知';
                    break;
            }
            $val['date'] = date('Y-m-d H:i',$val['time']);
      
        }
        return $val;
    }





    //
    /**
     * 获取订单4信息（顺风车订单）
     * 
     * @ApiInternal()
     * @param int $order_id 订单id
     * @return void
     */
    public function GetOrder4Data($order_id)
    {
        $val = Db::name('order_return')->find($order_id);
        if($val){

            $val = $this->GetOrder4FieldData($val);
            // $val['s_addr'] = $this->GetAddrData($val['s_addr_id']);
            // $val['e_addr'] = $this->GetAddrData($val['e_addr_id']);
            // if($val['s2_addr_id']>0)
            //     $val['s2_addr'] = $this->GetAddrData($val['s2_addr_id']);
            // if($val['e2_addr_id']>0)
            //     $val['e2_addr'] = $this->GetAddrData($val['e2_addr_id']);
        }
        return $val;
    }



    /**
     * 货主获取订单4信息（顺风车订单）
     * 
     * @ApiInternal()
     * @param int $order_id 订单id
     * @return void
     */
    public function OwnerGetOrder4Data($order_id)
    {
        $val = Db::name('order_return')->find($order_id);
        if($val){

            $val = $this->GetOrder4FieldData($val);
            if($val['s_uid']){ //如果有人接单了 判断是否是自己
                if($val['s_uid']!=$this->auth->id){
                    $this->error('已被抢单');
                }
            }
           
        }else{
            $this->error('没有该订单信息');
        }
        return $val;
    }


    /**
     * 获取订单4信息（顺风车订单）
     * 
     * @ApiInternal()
     * @param int $val 内容
     * @return void
     */
    public function GetOrder4FieldData($val)
    {
     
        if($val){
            $val['s_addr'] = $this->GetAddrData($val['s_addr_id']);
            $val['e_addr'] = $this->GetAddrData($val['e_addr_id']);
            if($val['s2_addr_id']>0)
                $val['s2_addr'] = $this->GetAddrData($val['s2_addr_id']);
            if($val['e2_addr_id']>0)
                $val['e2_addr'] = $this->GetAddrData($val['e2_addr_id']);
            $val['tag_list'] =Db::name('tag')->where('id','in',$val['tag_ids'])->select();

            if($val['car2_id']){
                $val['car'] = Db::name('car2')->where('id',$val['car2_id'])->find();
            }
            // switch ($val['lay_status']) {
            //     case '1':
            //         $val['lay'] = '一装一卸';
            //         break;
            //     case '2':
            //         $val['lay'] = '一装两卸';
            //         break;
            //     case '3':
            //         $val['lay'] = '两装一卸';
            //         break;
            //     case '4':
            //         $val['lay'] = '两装两卸';
            //         break;                
            //     default:
            //         $val['lay'] = '未知';
            //         break;
            // }

            // switch ($val['load_status']) {
            //     case '1':
            //         $val['load'] = '整车';
            //         break;
            //     case '2':
            //         $val['load'] = '零担';
            //         break;                
            //     default:
            //         $val['load'] = '未知';
            //         break;
            // }
            $val['date'] = date('Y-m-d H:i',$val['time']);
      
        }
        return $val;
    }

    //


    /**
     * 司机获取订单2信息（城市快运/搬家订单）
     * 
     * @ApiInternal()
     * @param int $order_id 订单id
     * @return void
     */
    public function DriverGetOrder2Data($order_id)
    {
        $val = Db::name('order2')->find($order_id);
        if($val){

            $val = $this->GetOrder2FieldData($val);
            if($val['j_uid']){ //如果有人接单了 判断是否是自己
                if($val['j_uid']!=$this->auth->id){
                    $this->error('已被抢单');
                }
            }
            $val['user'] = $this->GetSuserData($val['s_uid']);
        }else{
            $this->error('没有该订单信息');
        }
        return $val;
    }



    /**
     * 获取订单2信息（城市快运/搬家订单）
     * 
     * @ApiInternal()
     * @param int $order_id 订单id
     * @return void
     */
    public function GetOrder2Data($order_id)
    {
        $val = Db::name('order2')->find($order_id);
        if($val){

            $val = $this->GetOrder2FieldData($val);
        }
        return $val;
    }


    /**
     * 获取订单2信息（城市快运/搬家订单）
     * 
     * @ApiInternal()
     * @param int $val 内容
     * @return void
     */
    public function GetOrder2FieldData($val)
    {
     
        if($val){
            $val['s_addr'] = $this->GetAddrData($val['s_addr_id']);
            $val['e_addr'] = $this->GetAddrData($val['e_addr_id']);
            $val['tag2_list'] =Db::name('tag2')->where('id','in',$val['tag2_ids'])->select();
            
            $val['s_load_date'] = date('Y-m-d H:i',$val['s_load_time']);
            $val['car'] = Db::name('car')->where('id',$val['car_id'])->find();


            switch ($val['type_status']) {
                case '1':
                    $val['type_status_str'] = '运货';
                    break;
                case '2':
                    $val['type_status_str'] = '搬家';
                    break;                
                default:
                    $val['type_status_str'] = '未知';
                    break;
            }
            $val['date'] = date('Y-m-d H:i',$val['time']);
      
        }
        return $val;
    }

//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/2
//      |_|                                         | 获取订单信息 End










//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/2
//      |_|                                         | VIP Start


    /**
     * 添加司机用户Vip到期时间于订单
     *
     * @ApiInternal()
     * @param int $order 订单号
     * @return void
     */
    public function AddUserJVipEtimeByOrder($order)
    {
        
        $order_data = Db::name('jvip_order')->where('order',$order)->find();
        if($order_data['pay_status']!='2'){
            $this->error('该订单未支付',$order_data);
        }

        if($order_data['after']>0){
            //已添加过
        }else{
            $user = Db::name('user')->where('id',$order_data['uid'])->find();


            if($user['jvip_etime']<time()){
                $data['before'] = time();
            }else{
                $data['before'] = $user['jvip_etime'];
            }
    
            $data['after'] = $data['before'] + 31536000*$order_data['num'];
            $user_data['jvip'] = 2;//VIP:1=普通用户 ,2=VIP
            $user_data['jvip_etime'] = $data['after'];
            Db::name('user')->where('id',$order_data['uid'])->update($user_data);
            Db::name('jvip_order')->where('order',$order)->update($data);
        }



        // return $order;
    }




    /**
     * 添加用户Vip到期时间于订单
     *
     * @ApiInternal()
     * @param int $order 订单号
     * @return void
     */
    public function AddUserSVipEtimeByOrder($order)
    {
        
        $order_data = Db::name('svip_order')->where('order',$order)->find();
        if($order_data['pay_status']!='2'){
            $this->error('该订单未支付',$order_data);
        }

        if($order_data['after']>0){
            //已添加过
        }else{
            $user = Db::name('user')->where('id',$order_data['uid'])->find();


            if($user['svip_etime']<time()){
                $data['before'] = time();
            }else{
                $data['before'] = $user['svip_etime'];
            }
    
            $data['after'] = $data['before'] + 31536000*$order_data['num'];
            $user_data['svip'] = 2;//VIP:1=普通用户 ,2=VIP
            $user_data['svip_etime'] = $data['after'];
            Db::name('user')->where('id',$order_data['uid'])->update($user_data);
            Db::name('user')->where('id',$order_data['uid'])->setInc('svip_year',$order_data['num']);//增加购买的年
            Db::name('svip_order')->where('order',$order)->update($data);
        }



        // return $order;
    }






//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/2
//      |_|                                         | VIP End




//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/13
//      |_|                                         | TpMeCms 🛢Start

    /**
     * 获取加油站信息更具用户id🛢
     * @ApiInternal()
     * 
     * @param int $uid 用户id
     * @return void
     */
    public function GetPfsDataByUid($uid)
    {
        $data['uid'] = $uid;
        $pfs = Db::name('pfs')->where($data)->find();
        if(!$pfs){
            $this->error('您没有加油站');
        }
     
        $pfs['pfs_price'] = $this->GetPfsPrice($pfs['id']);
        return $pfs;
    }


    /**
     * 获取加油站信息更具id🛢
     * @ApiInternal()
     * 
     * @param int $id id
     * @return void
     */
    public function GetPfsDataById($id)
    {
        $data['id'] = $id;
        $pfs = Db::name('pfs')->where($data)->find();
        if(!$pfs){
            $this->error('没有该加油站');
        }
     
        $pfs['pfs_price'] = $this->GetPfsPrice($pfs['id']);
        return $pfs;
    }


    /**
     * 获取加油站价格🛢
     * @ApiInternal()
     * 
     * @param int $pfs_id 加油站id
     * @return void
     */
    public function GetPfsPrice($pfs_id)
    {
        $pfs_price = Db::name('pfs_price')->where('pfs_id',$pfs_id)->select();
        foreach ($pfs_price as $key => &$val) {
            $val['oil_name'] = Db::name('oil')->where('id',$val['oil_id'])->value('name');
        }
        return $pfs_price;
    }


//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/13
//      |_|                                         | TpMeCms 🛢End




    /**
     * 获取维修店铺信息更具用户id🚛🚚🚚
     * @ApiInternal()
     * 
     * @param int $uid 用户id
     * @return void
     */
    public function GetRepairDataByUid($uid)
    {
        $data['uid'] = $uid;
        $Repair = Db::name('repair')->where($data)->find();
        if(!$Repair){
            $this->error('您没有维修店铺');
        }
        return $Repair;
    }


    /**
     * 获取维修店铺信息更具id🚛🚚🚚
     * @ApiInternal()
     * 
     * @param int $id id
     * @return void
     */
    public function GetRepairDataById($id)
    {
        $data['id'] = $id;
        $Repair = Db::name('repair')->where($data)->find();
        if(!$Repair){
            $this->error('没有该维修店铺');
        }
        return $Repair;
    }






//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/13
//      |_|                                         | TpMeCms 🚛🚚🚚Start

    /**
     * 获取物流专线信息更具用户id🚛🚚🚚
     * @ApiInternal()
     * 
     * @param int $uid 用户id
     * @return void
     */
    public function GetLogisticsDataByUid($uid)
    {
        $data['uid'] = $uid;
        $Logistics = Db::name('logistics')->where($data)->find();
        if(!$Logistics){
            $this->error('您没有物流专线');
        }
     
        $Logistics['Logistics_route'] = $this->GetLogisticsRoute($Logistics['id']);
        return $Logistics;
    }


    /**
     * 获取物流专线信息更具id🚛🚚🚚
     * @ApiInternal()
     * 
     * @param int $id id
     * @return void
     */
    public function GetLogisticsDataById($id)
    {
        $data['id'] = $id;
        $Logistics = Db::name('logistics')->where($data)->find();
        if(!$Logistics){
            $this->error('没有该物流专线');
        }
     
        $Logistics['logistics_route'] = $this->GetLogisticsroute($Logistics['id']);
        return $Logistics;
    }


    /**
     * 获取物流专线路线🚛🚚🚚
     * @ApiInternal()
     * 
     * @param int $Logistics_id 物流专线id
     * @return void
     */
    public function GetLogisticsRoute($Logistics_id)
    {
        $Logistics_route = Db::name('logistics_route')->where('Logistics_id',$Logistics_id)->select();
        foreach ($Logistics_route as $key => &$val) {
            $val['route_name'] = Db::name('route')->where('id',$val['route_id'])->value('name');
        }
        return $Logistics_route;
    }


    /**
     * 获取全部路线🚛🚚🚚
     * @ApiInternal()
     * @return void
     */
    public function GetAllRoute($s_area_id=null,$e_area_id=null)
    {
        $where = null;
        if($s_area_id){
            $where['s_area_id'] = ['=',$s_area_id];
        }
        if($e_area_id){
            $where['e_area_id'] = ['=',$e_area_id];
        }

        $list = Db::name('route')->where($where)->select();
        foreach ($list as $key => &$val) {
            $val['s_area'] = Db::name('area')->where('id',$val['s_area_id'])->value('name');
            $val['e_area'] = Db::name('area')->where('id',$val['e_area_id'])->value('name');
        }
        return $list;
    }


//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/13
//      |_|                                         | TpMeCms 🚛🚚🚚End








//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/13
//      |_|                                         | TpMeCms 🛻Start

    /**
     * 获取二手车店铺信息更具用户id🛻
     * @ApiInternal()
     * 
     * @param int $uid 用户id
     * @return void
     */
    public function GetCarStoreDataByUid($uid)
    {
        $data['uid'] = $uid;
        $car_store = Db::name('car_store')->where($data)->find();
        if(!$car_store){
            $this->error('您没有二手车店铺');
        }
     
        $car_store['used_car_list'] = $this->GetStoreCarList($car_store['id']);
        return $car_store;
    }


    /**
     * 获取二手车店铺信息更具id🛻
     * @ApiInternal()
     * 
     * @param int $id id
     * @return void
     */
    public function GetCarStoreDataById($id)
    {
        $data['id'] = $id;
        $car_store = Db::name('car_store')->where($data)->find();
        if(!$car_store){
            $this->error('没有该二手车店铺');
        }
     
        $car_store['used_car_list'] = $this->GetStoreCarList($car_store['id']);
        return $car_store;
    }


    /**
     * 获取二手车店铺车列表🛻
     * @ApiInternal()
     * 
     * @param int $car_store_id 二手车店铺id
     * @return void
     */
    public function GetStoreCarList($car_store_id)
    {
        $used_car_list = Db::name('used_car')->where('car_store_id',$car_store_id)->select();
        foreach ($used_car_list as $key => &$val) {
            //$val['route_name'] = Db::name('route')->where('id',$val['route_id'])->value('name');
        }
        return $used_car_list;
    }


    
    /**
     * 获取二手车信息🛻
     * @ApiInternal()
     * 
     * @param int $id 二手车id
     * @return void
     */
    public function GetUsedCarData($id)
    {
        $used_car = Db::name('used_car')->where('id',$id)->find();
        // $used_car[''] = 
        return $used_car;
    }

    /**
     * 获取车品牌列表🛻
     * @ApiInternal()
     * 
     * @return void
     */
    public function GetCarbrandList()
    {
        return Db::name('carbrand')->order('weigh desc')->select();
    }


    /**
     * 获取车类型列表🛻
     * @ApiInternal()
     * 
     * @return void
     */
    public function GetCartypeList()
    {
        return Db::name('cartype')->order('weigh desc')->select();
    }
//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/09/13
//      |_|                                         | TpMeCms 🛻End










//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/10/09
//      |_|                                         | TpMeCms 支付配置Strat


    /**
     * @ApiInternal
     * 获取支付宝支付配置
     * @param integer $pay_role 1默认货主,2=司机
     *
     * @return void
     */   
    public function get_alipay_params($pay_role=1){

        $params = new \Yurun\PaySDK\AlipayApp\Params\PublicParams;
        $config = Config::get('site');

        if($pay_role==1){
            $params->appID = $config['ali_app_id'];
            $params->apiDomain = $config['ali_apiDomain'];
            $params->format = 'JSON';
            $params->sign_type = 'RSA2';
            // $params->isUseAES = true;
            // // 使用公钥证书模式
            $params->usePublicKeyCert = true;
            // 支付宝公钥证书文件路径
            $params->alipayCertPath = './cert/alipayCertPublicKey_RSA2.crt';
            // 支付宝根证书文件路径
            $params->alipayRootCertPath = './cert/alipayRootCert.crt';
            // 支付宝应用公钥证书文件路径
            $params->merchantCertPath = './cert/appCertPublicKey_2021003105661387.crt';

            $params->aesKey   = 'UlZ8TAMN688HF/MTWDqE2g==';
        
            //应用公钥2048
            $params->appPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgu1NlQM8kIhHzYsNPl46SiKjUtz2E6YrGTdeNE4YijeX7zOHtYxNxzAb5aR4kSuUdJL7mwpa9t+gY/qthWFlrQnQ5jFtTwNVP5rGt4gJ2cs3DHrr1TksiHZKvXGtPTQcVGPyaDXnRNgxO6OdGoJzKbFJmctpIc/9fNIiLKeCfT5s8jPrxwAYQUTzWRMqCQdPgaF1OnB2KWQ2ZHtI3YYx2j8qJK4rMTTYmPS7Xcn0Eln6iE8S5/vLpe6h8LYGKMRiNiBzb27wC2hyFRD4BBqk6n9iGSarBHk9E0Pqv0lIAaGKkqnaJNkTWksvhQBLUzCk4Z3ZqfHKsGD0ftHwbrMHpQIDAQAB';
            // $params->appPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAonceSr0yP2Uh8zE5wglwKlYZ/ylZDHhPY7meaD6AM856vyCojgjRRDYh1cKK9CDZxIxNdffuUfUQrN1HdhP0Sxv92qWhr0eNNUrnx930+ljnxE73eS+DtuwJGqcufA2/1ByT/VRgPKJ/dP/2LRIb3ktKnIt2/1tGj/wWr1hjbltSWu55qxKJpTD2BRjsW7fmfesTZKbnUQvdh6svUhyHvYId2wHzjeifvCeppF0Okufm8JOz6T6Iyy/i0JmbSMcF9duY834z2GwJpn9GNYkX5HkPQ+OS+thIiTcQiCQrg5v8bvpuyCJ55S20MvXMiWcmS59kmOCMRxRFs8HMdO5a4wIDAQAB';//$appPublicKey;
            //应用私钥2048.txt   支付宝开发工具生成
            $params->appPrivateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCidx5KvTI/ZSHzMTnCCXAqVhn/KVkMeE9juZ5oPoAzznq/IKiOCNFENiHVwor0INnEjE119+5R9RCs3Ud2E/RLG/3apaGvR401SufH3fT6WOfETvd5L4O27Akapy58Db/UHJP9VGA8on90//YtEhveS0qci3b/W0aP/BavWGNuW1Ja7nmrEomlMPYFGOxbt+Z96xNkpudRC92Hqy9SHIe9gh3bAfON6J+8J6mkXQ6S5+bwk7PpPojLL+LQmZtIxwX125jzfjPYbAmmf0Y1iRfkeQ9D45L62EiJNxCIJCuDm/xu+m7IInnlLbQy9cyJZyZLn2SY4IxHFEWzwcx07lrjAgMBAAECggEAKGZosPs1SJB0jc4a58aDDvQUSOBWVYSBcXISEygfp0JcQbT0VUWaDFVNuqNC/IxCut6M0J4TtGu1dtcb0yAJKrhOOxXfDABF/A+hbZEjPzHmiGl+nrMTFOTDKs6R/6VHo45rup5FxC5Ada7E39ZV+cRNTHpd4AgpltqAJaBcMW+69rPESGnOCfk+sEdfVOfp4qntJtzaVX2F/nGKk/7A1RsydcZMo06Pu2fA0C7o5Hvlc/q1Sc33uWB0c+wLbXjSR99MhP9tQ3k2rB4lglGgIy/IGrMXYe7xQC9yOhvEpTUMCfL/JmKxZCmCEuzwouso/esNMYfLbQdCI60PcQ2E2QKBgQD1L61czyIGGkyIBlrQAhCmrgtQbEMbh12KK8GqpaZvG2F0ObI06x3jiOgyCzH985rf1GZSbWkBiOV9OwFsy8Ist+g6nB1HQWqt4KcsGaV1Rs2RvhLVWdxgN/w4GtACQzelGt5xYRD9Bj5mtE0FJLgOonyQ4n8TOqx3bBuwBeZXBQKBgQCpoXbiAzmRCiBAqwgScxTVnTOhuAhKnLXDiIgIEO1XbAsF8uuk6WXq/v5+ZquG8pMSlEP7IqdGRJDF7w/Pth13spOWkqGvlHgAeGeOnGXJt5MHGuqkgr1+vTLT4O1ScHrxERzGElLqtNJ1Vxbu4u+HnQIq3ogZu4slpq5/XQ++xwKBgQCz6epSggO7aqzh25fjrsA9LtVKjEap+qie7QDNkYQRX4whVvz3a9eg0SNhJWnnqUvqFteGgJZe8+9B93xSMyom2kRkTY4GbXA0avcAm0kYR34tBcaYG7pkOHCxUqt0HZLFanPzyoBGysAbaQ5jSdBtnLm/LxSELbfEYeXnQk0FaQKBgQCpWecLa7bMQ7TBez8a1EPnpANJICc+/kdFSIiurN+XWOmEbequgMncm+lOHoh+uKz2bomULxubPpbe1XYOpD21I9bPC+NaHLrVlV+l9CR3B8xE2q2JwnEXGCKnf7bPiDZld/UnFmIrqo020tS1eGE1Hh5s2DA+qIsZ8tfhlfJDPwKBgAicnhA49D+7/Sgle9yo1xB/q8L6mWd40FxCH1DQfA1lJ4Ix4TDdILRXfbBbJLqBHEf4HADOON0gvc2WMQt7EEYnCv4R13/8cAYSN0HaeS6pQFJfwT74DdQa8jw1JuBGhxMaIRn2v10LVKjtIUfoUBpk3u06KkPpgpnLp+rPsr1V';
        }else{
            $params->appID = $config['driver_ali_app_id'];
            $params->apiDomain = $config['driver_ali_apiDomain'];
            $params->format = 'JSON';
            $params->sign_type = 'RSA2';
            // $params->isUseAES = true;
            // // 使用公钥证书模式
            $params->usePublicKeyCert = true;
            // 支付宝公钥证书文件路径
            $params->alipayCertPath = './cert/driver/alipayCertPublicKey_RSA2.crt';
            // 支付宝根证书文件路径
            $params->alipayRootCertPath = './cert/driver/alipayRootCert.crt';
            // 支付宝应用公钥证书文件路径
            $params->merchantCertPath = './cert/driver/appCertPublicKey_2021002181608598.crt';

            $params->aesKey   = '2deHluumqLLVvDmE/ptZCA==';
        
            //应用公钥2048
            $params->appPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlsxYl24wNXmEIwUmNpalU0WXooBE4BiTXiMrNiZeFDJQxLJ0E+tq0a9PLSxHtSoCEpopv/UWPUB9JpxV2ZRe/HexC8lW70NG9uNQURzVD/0NQMTCu8zTMygMxDyaJ1AS+HtoD/oSoiQ/kNDrvLRpUAmss+DYPWxZtuLx4kIDkIjZ8ZkrShTGFcGr7EhUkmsGIWUxdmtq4HG/Lp7noW1yMBUUWUUFMqfr0dKu4c+e1Eiz73dPPhyGOroD8ZZt1BfkU7kKv1qKP01luiqles7eByS29pMu9UTOdZi11QCloJp5S6BByYov+LDNn2YkAr/fXbfRwnOvqAgnmd3sn0FnsQIDAQAB';//$appPublicKey;
            //应用私钥2048.txt   支付宝开发工具生成
            $params->appPrivateKey ='MIIEpAIBAAKCAQEAlsxYl24wNXmEIwUmNpalU0WXooBE4BiTXiMrNiZeFDJQxLJ0E+tq0a9PLSxHtSoCEpopv/UWPUB9JpxV2ZRe/HexC8lW70NG9uNQURzVD/0NQMTCu8zTMygMxDyaJ1AS+HtoD/oSoiQ/kNDrvLRpUAmss+DYPWxZtuLx4kIDkIjZ8ZkrShTGFcGr7EhUkmsGIWUxdmtq4HG/Lp7noW1yMBUUWUUFMqfr0dKu4c+e1Eiz73dPPhyGOroD8ZZt1BfkU7kKv1qKP01luiqles7eByS29pMu9UTOdZi11QCloJp5S6BByYov+LDNn2YkAr/fXbfRwnOvqAgnmd3sn0FnsQIDAQABAoIBAGIRKlvwcLGWAPS1WJCPj5yD2YT4XdJOqSfDP0rL0MrZneUNGKgLpUAP/jGmZkvOseJfF1+ah4f19G2zpbEF6G/PdvfvS/X1jqToV0cotPbc3k2MqAdxwLe4B/VmY+nFDVFDD/2z54JCiIQpGeVyfjpq0EF6q6XmXMGu/RbjT2YiU5j8AlqKnZyM74QrXLONUuKw+/ObPXbmSIYncKD0VBhtcGTW3JacGsm9nGEoPNwXC9QyO+LKCodbwga+mq1zrCTieoZxpaDwWOmqfMc4zRuCofvzfe3jQ6zjJ2SrbEtSMfG/Nnmwm7uQ+lE1q+yGRFhA0IGdz6JqV+ZZm/YrAkECgYEA9VPb3yfROz4qlpF0CMAtjOie+7iV0KWSMcPT8+tjDJ+n54AL0s+LmcWPtjRiTRn7GQ32cAeBNo/UL2YC1qlwMFO7gXT8khhaO2t84bgQIGLzh3DfXfDaIrOr5kAJIwnzWD3KoCbvamvwSoDR2YyVC9kyzdNgrNAxAAYWTjdB4m0CgYEAnVu92p5OQdTP1UUj6f4l45wr+CicrYKeAx6ImUYYr6H02L4sn1yMGzudcQ53KGyy5njbSEYqBPYiZGZIsSmn6OcJDGV3uZ7H9HPNj5C8pgWMVRV3f8zWNAJ3dv+Bp8no9BnpqwAADtQzrs9jgr3x1KfhGoEFHcybuUS5Z8WWL9UCgYAeVghSR/IviThq9gGLM3hufDVsmx6rdk3lqXmEKA9PeE6i6cqMfu2cTjm/JishrZzHNFrM76CixpZOZibjtIAS+cet8nFo/2no/xmqL8COwK2sieCVFTtkHyOajUCT/J8CwmFT/HyOhFpqXBOW+zNTC8CkgwbpV7U3c4k+ksaq4QKBgQCF95wL6qivbTG/3Uw1I1U4kTXx4Ql6wvApsa4T59SOenDMsiOlTRJPARMKNImH1fr9MjlmL64IaVBgb6BFjDRSmZdfgWdLlX2ghZKlPlENez29FjiVilt3Df6NRfwpUEHOx9zi424pMcoKcq/CmFmxdXe0q9EiTJbrRTIfwd0aPQKBgQCCAP9mydZr0OxwAgvn8kHmyQBPcNDwUO7sgYaDplxEKFiYKAhgFDA6pyP8vbQKXWRnl3mm54U8yKMqBBOgjWgX9fJjx7r2j2sRuSbJy8xw1w6y/Uxo5wzH+qaxev/vGQ3wJTzcDf3w1i4I4BCDnTbut1MnEE/mV0WiYIuFkA/5Gg==';
        }
        return $params;      
    }






    /**
     * @ApiInternal
     * 🔐获取微信支付配置
     *
     * @param integer $pay_role 1默认货主,2=司机
     * @return void
     */
    public function get_wxpay_params($pay_role=1){
        $config = Config::get('site');
        if($pay_role==1){
            $params = new \Yurun\PaySDK\Weixin\Params\PublicParams;
            $params->appID = $config['app_id'];//appid
            $params->mch_id = $config['mch_id'];//商户号
            $params->key = $config['key'];//秘匙
        }else{
            //司机端
            $params = new \Yurun\PaySDK\Weixin\Params\PublicParams;
            $params->appID = $config['driver_app_id'];//appid
            $params->mch_id = $config['driver_mch_id'];//商户号
            $params->key = $config['driver_key'];//秘匙
        }
        return $params;      
    }



//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2021/10/09
//      |_|                                         | TpMeCms 支付配置Strat
}
